package main

import "fmt"

func BinaryFind(arr *[6]int, leftIndex int, rightIndex int, findVal int) {
	if leftIndex > rightIndex {
		fmt.Println("找不到")
		return
	}
	middle := (leftIndex + rightIndex) / 2
	if arr[middle] > findVal {
		BinaryFind(arr, leftIndex, middle-1, findVal)
	} else if arr[middle] < findVal {
		BinaryFind(arr, middle+1, rightIndex, findVal)
	} else {
		fmt.Println("找到了", findVal)
	}
}
func main() {
	names := []string{"白眉鹰王", "金毛狮王", "紫衫龙王", "青翼蝠王"}
	var heroName = ""
	fmt.Println("请输入要查找的人名")
	fmt.Scanln(&heroName)
	//顺序查找
	//for i:=0;i<len(names) ;i++  {
	//	if heroName==names[i]{
	//		fmt.Println("找到了",heroName)
	//		break
	//	}else if i == (len(names)-1){
	//		fmt.Println("没找到")
	//	}
	//}
	index := -1
	for i := 0; i < len(names); i++ {
		if heroName == names[i] {
			index = i
			break
		}
	}
	if index != -1 {
		fmt.Println("找到了", heroName)
	} else {
		fmt.Println("没有找到")
	}
	arr := [6]int{11, 22, 33, 44, 55, 66}
	BinaryFind(&arr, 0, len(arr)-1, 55)

}
